package net.googlecode.exigenlab.task5;

import net.googlecode.exigenlab.task5.calculator.Calculator;
import net.googlecode.exigenlab.task5.calculator.SalaryCalculatorFactory;
import net.googlecode.exigenlab.task5.model.Boss;
import net.googlecode.exigenlab.task5.model.Employee;
import net.googlecode.exigenlab.task5.model.Manager;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;

/**
 * Main application for for creating collection of persons and print reports.
 */
public class SalaryApp {

    private static final BigDecimal BOSS_TAX = new BigDecimal(500);
    private static final BigDecimal MANAGER_TAX = new BigDecimal(250);
    private static final BigDecimal EMPLOYEE_TAX = new BigDecimal(125);

    public static void main(String[] args) {
        Task5 task5 = new Task5();
        ArrayList<Manager> list = new ArrayList<Manager>();
        Collections.addAll(list, createBoss(), createEmployee(), createEmployeeTwo(),
                createManager(), createManagerTwo(), createManagerTree());

        if (args.length > 0)
        {
            if (args[0].equals("code")) {
                task5.codeSort(list);
            } else {
                if (args[0].equals("name")) {
                    task5.nameSort(list);
                } else {
                    if (args[0].equals("salary")) {
                        task5.salarySort(list);
                    } else {
                        System.out.println("Wrong parameter.");

                    }
                }
            }
        }
    }

    private static BigDecimal calculateSalary(Manager person, BigDecimal tax) {
        Calculator salaryCalculator = SalaryCalculatorFactory.getCalculator(person);
        salaryCalculator.setTax(tax);
        return salaryCalculator.calculateSalary(person);
    }

    public static Manager createManager() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanov");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        manager.setSalary(calculateSalary(manager, MANAGER_TAX));
        return manager;
    }


    public static Manager createManagerTwo() {
        Manager manager = new Manager();
        manager.setFirstName("Ivan");
        manager.setLastName("Ivanovenko");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(25));
        manager.setSalary(calculateSalary(manager, MANAGER_TAX));
        return manager;
    }

    public static Manager createManagerTree() {
        Manager manager = new Manager();
        manager.setFirstName("Anton");
        manager.setLastName("Antonov");
        manager.setAge(30);
        manager.setPerHour(true);
        manager.setBonus(false);
        manager.setRate(new BigDecimal(30));
        manager.setSalary(calculateSalary(manager, MANAGER_TAX));
        return manager;
    }

    public static Boss createBoss() {
        Boss boss = new Boss();
        boss.setFirstName("Petr");
        boss.setLastName("Petrov");
        boss.setAge(35);
        boss.setBonusAmount(new BigDecimal(1000));
        boss.setRate(new BigDecimal(50));
        boss.setSalary(calculateSalary(boss, BOSS_TAX));
        return boss;
    }

    public static Employee createEmployee() {
        Employee employee = new Employee();
        employee.setFirstName("Semen");
        employee.setLastName("Semenov");
        employee.setAge(55);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1500));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(8));
        employee.setSalary(calculateSalary(employee, EMPLOYEE_TAX));
        return employee;
    }

    public static Employee createEmployeeTwo() {
        Employee employee = new Employee();
        employee.setFirstName("Andrey");
        employee.setLastName("Andreev");
        employee.setAge(55);
        employee.setBonus(true);
        employee.setBonusAmount(new BigDecimal(1000));
        employee.setPerHour(true);
        employee.setRate(new BigDecimal(10));
        employee.setSalary(calculateSalary(employee, EMPLOYEE_TAX));
        return employee;
    }
}
